/*
 * Table.java
 */

package org.owasp.scrubbr.db;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;


public class Table {
    
    private String name;
    
    private ArrayList<String> scannableColumns = new ArrayList<String>();
    private ArrayList<String> allColumns = new ArrayList<String>();
    private int failedRowScans;
    
    private ArrayList<Column> columns = new ArrayList<Column>();
    private long rows = 0;
    private long taintedTuples = 0;
    private ArrayList<TaintedRow> taintedRows = new ArrayList<TaintedRow>();
    
    public int getFailedRowScans() {
        return failedRowScans;
    }
    
    public void incrementFailedRowScans() {
        failedRowScans++;
    }
    
    public Table(String name) {
        this.name = name;
    }
    
    public String getName() {
        return name;
    }
    
    public long getTaintedTuples() {
        return taintedTuples;
    }

    public void addColumn(Column column) {
        columns.add(column);
        
        if ( column.isScannable() ) {
            scannableColumns.add(column.getName());
        }
        
        allColumns.add(column.getName());
        
    }
    
    public void incrementRows() {
        rows++;
    }
    
    public long getRowCount() {
        return rows;
    }
    
    public List<String> getScannableColumns() {
        return scannableColumns;
    }
    
    public List<String> getAllColumns() {
        
        return allColumns;
        
    }
    
    public void addTaintedRow(TaintedRow row) {
        
        Iterator it = row.getAllTuples().iterator();
        
        int i=0;
        
        while(it.hasNext()) {
            Tuple t = (Tuple)it.next();
            if ( t.isTainted()) {
                i++;
            }
        }
        
        taintedTuples += i;
        
        taintedRows.add(row);
    }
    
    public List<TaintedRow> getTaintedRows() {
        return taintedRows;
    }
}
